package com.zzyl.controller;

import com.aliyun.iot20180120.models.DeleteDeviceRequest;
import com.aliyun.iot20180120.models.QueryDeviceDetailRequest;
import com.aliyun.iot20180120.models.QueryDevicePropertyStatusRequest;
import com.aliyun.iot20180120.models.QueryThingModelPublishedRequest;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ Description: 管理端 - 物联网iot相关接口
 * @ BelongsProject: zzyl-cp
 * @ Author: G攀
 * @ CreateTime: 2024-09-09  11:33
 * @ Version: 1.0
 */
@Api(tags = "管理端 - 物联网iot相关接口")
@RequestMapping("/iot")
@RestController
public class DeviceController {

    @Autowired
    private DeviceService deviceService;

    @PostMapping("/syncProductList")
    @ApiOperation("从物联网平台同步产品列表")
    public ResponseResult syncProductList() {
        deviceService.syncProductList();
        return ResponseResult.success();
    }

    /**
     * 查询所有产品列表
     */
    @GetMapping("/allProduct")
    @ApiOperation("查询所有产品列表")
    public ResponseResult<List<ProductVo>> allProduct() {
        List<ProductVo> productVoList = deviceService.allProduct();
        return ResponseResult.success(productVoList);
    }

    /**
     * 注册设备
     */
    @PostMapping("/RegisterDevice")
    @ApiOperation("注册设备")
    public ResponseResult RegisterDevice(@RequestBody DeviceDto dto) {
        deviceService.RegisterDevice(dto);
        return ResponseResult.success();
    }

    /**
     * 分页查询设备列表
     */
    @GetMapping("/pageQueryDevice")
    @ApiOperation("分页查询设备列表")
    public ResponseResult<PageResponse> page(DevicePageQueryDto pageQueryDto) {
        return deviceService.page(pageQueryDto);
    }

    /**
     * 查询设备详情数据
     */
    @PostMapping("/QueryDeviceDetail")
    @ApiOperation("查询设备详细数据")
    public ResponseResult<DeviceVo> queryDeviceDetail(@RequestBody QueryDeviceDetailRequest queryDeviceDetailRequest) {
        return deviceService.queryDeviceDetail(queryDeviceDetailRequest);
    }

    /**
     * 查询指定设备的物模型运行状态
     */
    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation("查询指定设备的物模型运行状态")
    public ResponseResult queryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest request) {
        return deviceService.queryDevicePropertyStatus(request);
    }

    /**
     * 查看指定产品的已发布物模型中的功能定义详情
     */
    @PostMapping("/QueryThingModelPublished")
    @ApiOperation("查看指定产品的已发布物模型中的功能定义详情")
    public ResponseResult queryThingModelPublishedRequest(@RequestBody QueryThingModelPublishedRequest request) {
        return deviceService.queryThingModelPublishedRequest(request);
    }

    /**
     * 修改设备的备注名称
     */
    @PostMapping("/UpdateDevice")
    @ApiOperation("修改设备的备注名称")
    public ResponseResult updateDevice(@RequestBody DeviceDto dto) {
        deviceService.UpdateDevice(dto);
        return ResponseResult.success();
    }

    /**
     * 删除设备
     */
    @DeleteMapping("/DeleteDevice")
    @ApiOperation("删除设备")
    public ResponseResult DeleteDevice(@RequestBody DeleteDeviceRequest deleteDeviceRequest) {
        deviceService.DeleteDevice(deleteDeviceRequest);
        return ResponseResult.success();
    }
}
